
package msu.ml.core;

import msu.ml.data.*;
import weka.classifiers.*;
import weka.core.*;
import java.util.*;

/**
 *
 * @author Reginald M Mead
 * @version 1.0
 */
public class UpdateableExperiment extends Experiment
{
   public void trainClassifier(Classifier classifier, DataProvider dataProvider)
   {
      try
      {
         NxInstances [] trainingData = dataProvider.getNextIndividualTrainingData();
         for(int i = 0; i < trainingData.length; i++)
         {
            if(i == 0)
            {
               classifier.buildClassifier(trainingData[i]);
            }
            else
            {
               NxInstances temp = trainingData[i];
               for(int j = 0; j < temp.numInstances(); j++)
               {
                  Instance newInstance = temp.instance(j);
                  try
                  {
                     ((UpdateableClassifier)classifier).updateClassifier(newInstance);
                  }
                  catch(Exception e)
                  {
                     System.out.println("Classifier Error");
                     System.out.println(e);
                  }
               }
            }
         }
      }
      catch(Exception e) 
      {
         System.out.println("Updateable Training Error");
         System.out.println(e);
         System.out.println(e.getStackTrace());   
      }
   }
}
